<html>
<head><meta charset="utf-8"><title>Get crate &quot; declaration name&quot; · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Get.20crate.20.22.20declaration.20name.22.html">Get crate &quot; declaration name&quot;</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="189868602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Get%20crate%20%22%20declaration%20name%22/near/189868602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Get.20crate.20.22.20declaration.20name.22.html#189868602">(Mar 06 2020 at 07:30)</a>:</h4>
<p>I'm looking at the <a href="https://github.com/rust-analyzer/rust-analyzer/issues/1064" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/issues/1064">https://github.com/rust-analyzer/rust-analyzer/issues/1064</a> issue </p>
<p>So far I've got something like this:</p>
<p><a href="/user_uploads/4715/uAC1I10cCpB7eLBOFejcAb66/image.png" target="_blank" title="image.png">image.png</a> <br>
(note that  <code>input</code> string on the top, this is the mod path).</p>
<div class="message_inline_image"><a href="/user_uploads/4715/uAC1I10cCpB7eLBOFejcAb66/image.png" target="_blank" title="image.png"><img src="/user_uploads/4715/uAC1I10cCpB7eLBOFejcAb66/image.png"></a></div><p>But then I look at what intellij-rust does and see a crate "name" there:<br>
<a href="/user_uploads/4715/CqnGshs6w8ZUw8leY2vkse_L/image.png" target="_blank" title="image.png">image.png</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/CqnGshs6w8ZUw8leY2vkse_L/image.png" target="_blank" title="image.png"><img src="/user_uploads/4715/CqnGshs6w8ZUw8leY2vkse_L/image.png"></a></div><p>This way it looks way better, imo.</p>
<p>Yet, we lack the proper way to get that name, since the only crate-related names we operate is a name of a crate that is declared as a dependency.<br>
Is there a way to get the name of a crate that is used when the crate is declared?</p>



<a name="189872188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Get%20crate%20%22%20declaration%20name%22/near/189872188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Get.20crate.20.22.20declaration.20name.22.html#189872188">(Mar 06 2020 at 08:30)</a>:</h4>
<p>Not really at the moment</p>



<a name="189872211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Get%20crate%20%22%20declaration%20name%22/near/189872211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Get.20crate.20.22.20declaration.20name.22.html#189872211">(Mar 06 2020 at 08:31)</a>:</h4>
<p>It would be fine to add this info to <code>ra_ide</code> crate, but not to the <code>hir</code>. We used to have something similar for debugging infra, but we removed it when we split the hir</p>



<a name="189875225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Get%20crate%20%22%20declaration%20name%22/near/189875225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Get.20crate.20.22.20declaration.20name.22.html#189875225">(Mar 06 2020 at 09:23)</a>:</h4>
<p>Thanks.<br>
If you share a pointer to the removal PR, it will help.</p>



<a name="189876190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Get%20crate%20%22%20declaration%20name%22/near/189876190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Get.20crate.20.22.20declaration.20name.22.html#189876190">(Mar 06 2020 at 09:39)</a>:</h4>
<p>I thought you were talking about <a href="https://github.com/rust-analyzer/rust-analyzer/blob/dd7a11eec7cfc4703214c6278d4023cc372faa90/crates/ra_ide_db/src/lib.rs#L131-L135" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/dd7a11eec7cfc4703214c6278d4023cc372faa90/crates/ra_ide_db/src/lib.rs#L131-L135">this debugging infra</a>, but it wasn't removed</p>



<a name="189876292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Get%20crate%20%22%20declaration%20name%22/near/189876292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Get.20crate.20.22.20declaration.20name.22.html#189876292">(Mar 06 2020 at 09:40)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/commit/ef2b84ddf119c950272c5f1eb321f3f9e90bedd4" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/commit/ef2b84ddf119c950272c5f1eb321f3f9e90bedd4">https://github.com/rust-analyzer/rust-analyzer/commit/ef2b84ddf119c950272c5f1eb321f3f9e90bedd4</a></p>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/commit/32658a73b4c9078421a1cab92ec459bb5b7236f5" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/commit/32658a73b4c9078421a1cab92ec459bb5b7236f5">https://github.com/rust-analyzer/rust-analyzer/commit/32658a73b4c9078421a1cab92ec459bb5b7236f5</a></p>



<a name="190011413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Get%20crate%20%22%20declaration%20name%22/near/190011413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Get.20crate.20.22.20declaration.20name.22.html#190011413">(Mar 08 2020 at 11:59)</a>:</h4>
<p>What if we add the crate name info to <code>ra_db</code> level instead, making the <code>CrateData</code> to contain the <code>declaration_name</code> (or whatever better name used) with the property required?<br>
<code>add_crate_root</code> method can accept one more parameter.</p>



<a name="190011537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Get%20crate%20%22%20declaration%20name%22/near/190011537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Get.20crate.20.22.20declaration.20name.22.html#190011537">(Mar 08 2020 at 12:03)</a>:</h4>
<p>The main issue would be to get some name for the project.json case (<a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/rust-project.2Ejson/near/188152985" title="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/rust-project.2Ejson/near/188152985">https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/rust-project.2Ejson/near/188152985</a>), so we can keep this property <code>Optional</code> for a while or use some dummy  values for those crates instead.</p>



<a name="190012385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Get%20crate%20%22%20declaration%20name%22/near/190012385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Get.20crate.20.22.20declaration.20name.22.html#190012385">(Mar 08 2020 at 12:33)</a>:</h4>
<p>I now think that maybe we should store an optional display name in<br>
CrateGraph? It would be useful for profiling as well at least and,<br>
practically, it should be hard to misuse.</p>



<a name="190013003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Get%20crate%20%22%20declaration%20name%22/near/190013003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Get.20crate.20.22.20declaration.20name.22.html#190013003">(Mar 08 2020 at 12:56)</a>:</h4>
<p><code>CrateData</code> is also in the <code>CrateGraph</code>, so we're talking almost about the same.<br>
I'm a bit reluctant to make it optional, since every crate has its own declaration name, doesn't it?</p>



<a name="190015300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Get%20crate%20%22%20declaration%20name%22/near/190015300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Get.20crate.20.22.20declaration.20name.22.html#190015300">(Mar 08 2020 at 14:15)</a>:</h4>
<p>Actually, never mind, it should be optional, I've confused different kinds of crate names.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>